package com.lqk.demo.concurrencytools.threadpool.executors.scheduledthread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static com.lqk.demo.n2.util.Sleeper.sleep;

/**
 * @author lqk
 * @date 2022/1/10 14:36
 *
 * newScheduledThreadPool 延时执行任务
 *
 * 都是1秒后执行任务, 并行执行的
 */
@Slf4j
public class TestScheduledExecutorService {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);

        pool.schedule(()->{
            log.debug("task1");
            sleep(2);
        },1, TimeUnit.SECONDS);

        pool.schedule(()->{
            log.debug("task2");
        },1, TimeUnit.SECONDS);
    }
}
